package com.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class AdvisorTagHandler extends SimpleTagSupport{
	
	private String user;
	String[] movies={"Moonsoon Wedding", "saved!", "fahrenheit 9/11"};		
	
	public void doTag() throws JspException, IOException{
		for (int i = 0 ; i < movies.length ; i++) {
			getJspContext().setAttribute("movie", movies[i]);
			getJspBody().invoke(null);
		}
		
	/*	//태그 로직
		getJspContext().getOut().write("hello"+ user + "<br>");
		getJspContext().getOut().write("Your advice is : "+ getAdvice());
		
	//	getJspBody().invoke(null); 태그가 몸체를 갖는 경우를 에 사용하게 됨 
		//인자가 널인 것은 writer말고 response 로  출력하라는 뜻임 . 
*/	}
	

	public void setMovies(String[] movies) {
		this.movies = movies;
	}


	public void setUser(String user) {
		this.user = user;
	}


	private String getAdvice() {
		// TODO Auto-generated method stub
		String[] adviceStrings = {"Thart color's not working foryou.:", "You should call in sick.", "You might want to rethink that harct."};
		int random = (int) ((Math.random()*adviceStrings.length));
		
		return adviceStrings[random];
	}

}
